package com.yuteng.comment.controller;

import com.github.pagehelper.PageInfo;
import com.yuteng.comment.entity.Result;
import com.yuteng.comment.entity.VideoComment;
import com.yuteng.comment.service.impl.VideoCommentServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import com.yuteng.comment.service.VideoCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 评论表服务控制器
 *
 * @author 余腾
 * @description 用户喜欢的视频的一些信息
 * @since 2021-10-27 16:30:07
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/videoComment")
public class VideoCommentController {
    private final VideoCommentService videoCommentService;
    @Autowired
    VideoCommentServiceImpl commentService;
    @GetMapping
    public Result getAll(@RequestParam(defaultValue = "1")int pageNum,@RequestParam(defaultValue = "5")int pageSize){
        List list=new ArrayList();
        list.add(commentService.getAll(pageNum, pageSize));
        return new Result(true,200,"ok",list);
    }
    @PostMapping
    public Result addComment(@RequestBody VideoComment videoComment){
        return new Result(true,200,"ok",commentService.add(videoComment));
    }
    @PutMapping
    public Result updateComment(@RequestBody VideoComment videoComment){
        return new Result(true,200,"ok",commentService.updateComment(videoComment));
    }
    @DeleteMapping
    public Result deleteById(Long id){
        return new Result(true,200,"ok",commentService.deleteById(id));
    }
    @GetMapping("/user")
    public Result getVideoCommentByUserId(Long userId,@RequestParam(defaultValue = "1")int pageNum,@RequestParam(defaultValue = "5")int pageSize){
        PageInfo videoCommentByUserId = commentService.getVideoCommentByUserId(userId, pageNum, pageSize);
        List list=new ArrayList();
        list.add(videoCommentByUserId);
        return new Result(true,200,"ok",list);
    }
    @GetMapping("/video")
    public Result getVideoCommentByVideId(Long videoId,@RequestParam(defaultValue = "1")int pageNum,@RequestParam(defaultValue = "5")int pageSize){
        List list=new ArrayList();
        PageInfo videoCommentByVideId = commentService.getVideoCommentByVideId(videoId, pageNum, pageSize);
        list.add(videoCommentByVideId);
        return new Result(true,200,"ok",list);
    }
}